package com.xcdh.learn.commons;

import com.xcdh.domain.vo.R;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.Arrays;

@RestControllerAdvice
public class GlobalExceptionController {

    @ExceptionHandler(Exception.class)
    public R handlerException(Exception e){
        e.printStackTrace();
        return R.error() ;
    }


    @ExceptionHandler(HttpRequestMethodNotSupportedException.class)
    public R handlerException(HttpRequestMethodNotSupportedException e){
        e.printStackTrace();
        return R.error("该接口支持请求方式为："+ Arrays.toString(e.getSupportedMethods())+"") ;
    }

    @ExceptionHandler(HttpMessageNotReadableException.class)
    public R handlerException(HttpMessageNotReadableException e){
        e.printStackTrace();
        return R.error("该接口请求参数格式为：json ，请求头为Content-Type: application/json;charset=UTF-8") ;
    }

}
